const express = require("express");
const app = express();
const { createProxyMiddleware } = require("http-proxy-middleware");



// 设置代理
const apiProxy = createProxyMiddleware("/api", {
  target: "http://192.168.168.001:8080/gantt/api/v1", // 设置代理目标地址
  changeOrigin: true, // 将请求头中的 host 设置为目标地址
  pathRewrite: {
    "^/api": "", // 如果你的 API 地址有/api前缀，可以在请求时去掉
  },
});

// 使用代理中间件
app.use("/api", apiProxy);

app.use(express.static("dist"));

app.get("/", (req, res) => {
  res.sendFile(__dirname + "/dist/index.html");
});

// 启动服务器
const port = 8080;
app.listen(port, '0.0.0.0',() => {
  console.log(`Server is running on port ${port}`);
  console.log(`http://localhost:${port}`);
});
